﻿<UserControl x:Class="CBR.Views.LibraryView"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
             mc:Ignorable="d" 
             d:DesignHeight="300" d:DesignWidth="300"
             xmlns:Controls="clr-namespace:CBR.Components.Controls"
             xmlns:Converters="clr-namespace:CBR.Components.Converters"
			 Background="{DynamicResource CbrDarkBackgroundBrush}">

    <UserControl.Resources>

        <!--  view for explorer -->
        <GridView x:Key="LibraryGridView">
            <GridView.Columns>

                <GridViewColumn Width="{PropertyStateExtension Default=Auto}"
					  ElementState.Mode="Persist" ElementState.UId="LibraryShared" >
                    <GridViewColumnHeader Tag="IsShared"
										  Content="{LocalizationExtension ResModul=ByCode, Key=Core.Properties.Shared}"/>
                    <GridViewColumn.CellTemplate>
                        <DataTemplate>
                            <CheckBox VerticalAlignment="Center" HorizontalAlignment="Center" IsChecked="{Binding IsShared}" />
                        </DataTemplate>
                    </GridViewColumn.CellTemplate>

                </GridViewColumn>
                <GridViewColumn DisplayMemberBinding="{Binding Path=BookCount}" Width="{PropertyStateExtension Default=Auto}"
					  ElementState.Mode="Persist" ElementState.UId="LibraryBookCount" >
                    <GridViewColumnHeader Tag="BookCount"
										  Content="{LocalizationExtension ResModul=ByCode, Key=Core.Properties.BookCount}"/>
                </GridViewColumn>
                
                <GridViewColumn DisplayMemberBinding="{Binding Path=Title}" Width="{PropertyStateExtension Default=140}"
					  ElementState.Mode="Persist" ElementState.UId="LibraryGridViewFile">
                    <GridViewColumnHeader Tag="Title"
										  Content="{LocalizationExtension ResModul=ByCode, Key=Core.Properties.FileName}"/>
                </GridViewColumn>
                
                <GridViewColumn Width="{PropertyStateExtension Default=Auto}"
					  ElementState.Mode="Persist" ElementState.UId="ExplorerGridViewWidth" >
                    <GridViewColumnHeader Tag="Description"
										  Content="{LocalizationExtension ResModul=ByCode, Key=Core.Properties.Description}"/>
                    <GridViewColumn.CellTemplate>
                        <DataTemplate>
                            <TextBox Style="{DynamicResource CbrStandardTextBox}"
												 Text="{Binding Path=Description}" HorizontalAlignment="Stretch" />
                        </DataTemplate>
                    </GridViewColumn.CellTemplate>
                </GridViewColumn>

            </GridView.Columns>
        </GridView>

        <DataTemplate x:Key="LibraryImageViewTemplate">
            <Grid x:Name="MainItemGrid" Margin="2">
                <Border Background="{DynamicResource CbrLightBackground}">
					<Image x:Name="CoverImage" Source="{Binding Path=CoverImage}" Margin="10"/>
                </Border>
                <Grid VerticalAlignment="Bottom"  Background="{DynamicResource CbrDarkBackgroundBrush}" Opacity="0.7">
                    <StackPanel Orientation="Vertical" Margin="10,10,32,10">
                        <TextBlock Text="{Binding Title}" FontWeight="Bold" />
                        <TextBlock Text="{Binding Description}" />
                        <StackPanel Orientation="Horizontal">
                            <TextBlock Text="{Binding BookCount}" />
                            <TextBlock Text="{LocalizationExtension ResModul=ByCode, Key=Core.Properties.BookCount}"/>
                        </StackPanel>
                    </StackPanel>
                    <Image Source="/CBR;component/Resources/Images/32x32/icon/web.png" Width="32" HorizontalAlignment="Right"
                           Visibility="{Binding IsShared, Converter={x:Static Converters:BoolToVisibilityConverter.Instance}}" />
                </Grid>
            </Grid>
        </DataTemplate>

        <Controls:SimpleThumbView x:Key="LibraryImageView" ItemTemplate="{StaticResource LibraryImageViewTemplate}" />

        <!-- Style for an individual list view item -->
        <Style x:Key="ViewItemBase" TargetType="{x:Type ListViewItem}">
			<EventSetter Event="MouseDoubleClick" Handler="Item_MouseDoubleClick" />
            <Setter Property="Background" Value="Transparent" />
            <Setter Property="BorderBrush" Value="{DynamicResource CbrForegroundBrush}" />
            <Setter Property="Foreground" Value="{DynamicResource CbrForegroundBrush}" />
            <Setter Property="HorizontalContentAlignment" Value="Stretch" />
            <Setter Property="VerticalContentAlignment" Value="Center" />
        </Style>

        <Style x:Key="GridViewItemStyle" TargetType="{x:Type ListViewItem}" BasedOn="{StaticResource ViewItemBase}" >
            <Setter Property="BorderBrush" Value="{DynamicResource CbrForegroundBrush}" />
            <Setter Property="Height" Value="32" />
            <Setter Property="Template">
                <Setter.Value>
                    <ControlTemplate TargetType="{x:Type ListViewItem}" >
                        <Border SnapsToDevicePixels="True" HorizontalAlignment="Stretch" VerticalAlignment="Stretch"
								Background="{TemplateBinding Background}" BorderBrush="{TemplateBinding BorderBrush}"
								BorderThickness="0,0,0,1"
								ToolTipService.IsEnabled="{Binding DataContext.ShowTooltipExplorer,RelativeSource={RelativeSource Mode=FindAncestor, AncestorType={x:Type ListView}}}">

                            <GridViewRowPresenter />
                        </Border>

                        <ControlTemplate.Triggers>
                            <Trigger Property="IsSelected" Value="True">
                                <Setter Property="Background" Value="{DynamicResource CbrBackgroundSelected}"/>
                            </Trigger>
                            <Trigger Property="IsMouseOver" Value="True">
                                <Setter Property="Background" Value="{DynamicResource CbrBackgroundSelected}"/>
                            </Trigger>
                        </ControlTemplate.Triggers>
                    </ControlTemplate>
                </Setter.Value>
            </Setter>
        </Style>

        <Style x:Key="ThumbnailViewItemStyle" TargetType="{x:Type ListViewItem}" BasedOn="{StaticResource ViewItemBase}" >
            <Setter Property="Width" Value="200" />
            <Setter Property="Height" Value="200" />
            <Setter Property="Margin" Value="10" />
            <Setter Property="Template">
                <Setter.Value>
                    <ControlTemplate TargetType="{x:Type ListBoxItem}" >
                        <Border SnapsToDevicePixels="True" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" 
                            Background="{TemplateBinding Background}" BorderBrush="{TemplateBinding BorderBrush}">
                            <ContentPresenter />
                        </Border>
                        <ControlTemplate.Triggers>
                            <Trigger Property="IsSelected" Value="True">
                                <Setter Property="Background" Value="{DynamicResource CbrBackgroundSelected}"/>
                            </Trigger>
                            <Trigger Property="IsMouseOver" Value="True">
                                <Setter Property="Background" Value="{DynamicResource CbrBackgroundSelected}"/>
                            </Trigger>
                        </ControlTemplate.Triggers>
                    </ControlTemplate>
                </Setter.Value>
            </Setter>
        </Style>

    </UserControl.Resources>

    <Grid>

            <Controls:ExtendedListView x:Name="LibraryListView" Grid.Row="1" BorderThickness="0"
									   HorizontalAlignment="Stretch" Margin="1" VerticalAlignment="Stretch"
									   DragAndDropID="CBR.Book.Path" ItemsSource="{Binding Catalogs}"
									   ColumnOrder="{PropertyStateExtension Default=''}"
									   ElementState.Mode="Persist" ElementState.UId="LibraryListView"
									   ToolTipService.IsEnabled="{Binding ShowTooltipExplorer}" >
                
                <Controls:ExtendedListView.View>
                    <MultiBinding Converter="{x:Static Converters:StringToResourceConverter.Instance}">
                        <Binding RelativeSource="{RelativeSource AncestorType=UserControl}"/>
                        <Binding Path="CurrentViewMode" />
                    </MultiBinding>
                </Controls:ExtendedListView.View>
                <Controls:ExtendedListView.ItemContainerStyle>
                    <MultiBinding Converter="{x:Static Converters:StringToResourceConverter.Instance}">
                        <Binding RelativeSource="{RelativeSource AncestorType=UserControl}"/>
                        <Binding Path="CurrentItemStyle" />
                    </MultiBinding>
                </Controls:ExtendedListView.ItemContainerStyle>

            <Controls:ExtendedListView.ContextMenu>
                <ContextMenu>
                    <MenuItem Header="{LocalizationExtension ResModul=CBR, Key=Button.Open, DefaultValue=Open}"
                                  Command="{Binding ForwardCommand}" CommandParameter="CatalogOpenFileCommand">
                        <MenuItem.Icon>
                            <Image Source="/CBR;component/Resources/Images/32x32/library_open.png" />
                        </MenuItem.Icon>
                    </MenuItem>

					<MenuItem Header="{LocalizationExtension ResModul=CBR, Key=Button.ToggleShare, DefaultValue=Toggle share}"
                                  Command="{Binding ForwardCommand}" CommandParameter="CatalogShareCommand">
						<MenuItem.Icon>
							<Image Source="/CBR;component/Resources/Images/32x32/library_share.png" />
						</MenuItem.Icon>
					</MenuItem>
					
					<Separator></Separator>
                    
                    <MenuItem Header="{LocalizationExtension ResModul=CBR, Key=Button.Delete, DefaultValue=Delete}"
                                  Command="{Binding ForwardCommand}" CommandParameter="CatalogDeleteCommand">
                        <MenuItem.Icon>
                            <Image Source="/CBR;component/Resources/Images/32x32/library_delete.png" />
                        </MenuItem.Icon>
                    </MenuItem>

					<Separator></Separator>

					<MenuItem Header="{LocalizationExtension ResModul=CBR, Key=Button.RefreshCover, DefaultValue=Refresh cover}"
                                  Command="{Binding ForwardCommand}" CommandParameter="CatalogRefreshCoverCommand">
						<MenuItem.Icon>
							<Image Source="/CBR;component/Resources/Images/32x32/library_refresh.png" />
						</MenuItem.Icon>
					</MenuItem>

				</ContextMenu>
            </Controls:ExtendedListView.ContextMenu>
                
        </Controls:ExtendedListView>
        
    </Grid>
</UserControl>
